/**
 * @param {number[][]} points
 * @return {number}
 */
 var maxPoints = function(points) {
    const m = points.length, n = points[0].length
    const dp = new Array(m).fill(0).map(() => new Array(n).fill(0))
    for(let i = 0; i<n; i++){
        dp[0][i] = points[0][i]
    }
    const getMaxPoints = (arr,  index) => {
        let ans = 0
        for(let i = 0; i<n; i++){
            const p = arr[i] - Math.abs(i-index)
            if(p <= 0){
                continue
            }
            ans = Math.max(ans, p)
        }
        return ans
    }
    for(let i = 1; i<m; i++){
        for(let j = 0; j<n; j++){
            dp[i][j] = points[i][j] + getMaxPoints(dp[i-1], j)
        }
    }
    return Math.max(...dp[m-1])
};